package com.yh.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yh.common.BaseResult;
import com.yh.entity.SysPermission;
import com.yh.entity.vo.MenuVO;
import com.yh.security.SysUserDTO;
import com.yh.service.ISysPermissionService;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;

import java.util.List;

/**
 * <p>
 * 权限表 权限表 前端控制器
 * </p>
 *
 * @author yh
 * @since 2021-04-06
 */
@AllArgsConstructor
@RestController
@RequestMapping("/sysPermission")
public class SysPermissionController {
    private final ISysPermissionService sysPermissionService;

    @PostMapping
    public BaseResult createPermission(@RequestBody SysPermission sysPermission){
        SysPermission permission = sysPermissionService.createPermission(sysPermission);
        return BaseResult.ok(permission);
    }

    @PutMapping
    public BaseResult updatePermission(@RequestBody SysPermission sysPermission){
        SysPermission permission = sysPermissionService.updatePermission(sysPermission);
        return BaseResult.ok(permission);
    }

    @GetMapping
    public BaseResult getInfo(@RequestParam("id") Long id){
        SysPermission permission = sysPermissionService.getInfo(id);
        return BaseResult.ok(permission);
    }

    @PostMapping("/getPage")
    public BaseResult getInfo(@DefaultValue(value = "1")Integer pageNum, @DefaultValue(value = "10")Integer pageSize){
        Page<SysPermission> page = sysPermissionService.getPage(pageNum,pageSize);
        return BaseResult.ok(page);
    }

    @GetMapping("/getMenus")
    public BaseResult getMenus(){
        List<MenuVO> menuVOS = sysPermissionService.getMenus();
        return BaseResult.ok(menuVOS);
    }
}

